local filename = "getactivityinfo.lua"

local timetool = require "timetool"
local filelog = require "filelog"
local redisdao = require "redisdao"
require "pubenum"

local json = require "cjson"
json.encode_sparse_array(true,1,1)

local service = nil
local CMD = {
	service = nil
}

--
--获得活动配置信息
--activity_id 活动id
--
function CMD.process(rid, msgbody)
	if not service then
		service = CMD.service
	end
    msgbody = msgbody or {}

    local response = service:getactivityinfo(rid, msgbody)
    if response.retcode then
        return response
    end
    
    --设置流水红包相关数据, 流水红包1001
    if msgbody.activity_id == EACTIVITY_IDS.REDPACKET_WATER then
        local curtime = timetool.get_time()
        local record_time = service.lastupwatertime
        
        --获取当前流水
        if not record_time then
            local result, result_data = redisdao.query_data(".gmmqredis", "get", rid .. ":lastupwatertime")
            record_time = tonumber(result_data or 0) or 0
        end
        
        local curday = os.date("%d", curtime)
        local lastday = os.date("%d", record_time)
        if lastday ~= curday then    --重置流水和领取记录
            service.money.today_water = 0
            service.lastupwatertime = curtime
            redisdao.query_data(".gmmqredis", "del", rid .. ":rpwaterrecord")
        end
        response.today_water = service.money.today_water
        
        --获取领取记录
        local result, data = redisdao.query_data(".gmmqredis", "get", rid .. ":rpwaterrecord")
        if result and data then
            response.rpwater_recvrecord = tostring(data)         
        end
    end
    
	return response
end

return CMD
